package org.ting.j20250110_gobang.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.ting.j20250110_gobang.model.User;

@Mapper
public interface UserMapper {
    @Select("select * from user where username = #{username}")
    User getUserByName(String username);
    @Insert("insert into user(username, password, score, total_count, win_count) values (#{username}, #{password}, #{score}, #{totalCount}, #{winCount})")
    Integer insertUser(User user);
    //获胜
    @Update("update user set score = score + 30, total_count = total_count + 1, win_count = win_count + 1 where user_id = #{userId}")
    Integer userWin(int userId);
    //失败
    @Update("update user set score = score - 30, total_count = total_count + 1 where user_id = #{userId}")
    Integer userLose(int userId);
}
